<?php

namespace app\admin\model\ucenter;

use think\Model;
use app\common\model\Base;


class User extends Base
{
    protected $name = 'user';

    protected $pk = 'id';

    public function levels(){
        return $this->belongsTo(UserLevel::class,'level_id');
    }

    /**
     * 新增前，对数据进行特殊处理
     * @param Model $model
     * @return mixed|void
     */
    public static function onBeforeInsert(Model $user)
    {
        $user->password = md5($user->password);
        return true;
    }
    /**
     * 更新前，对数据进行特殊处理
     * @param Model $model
     * @return mixed|void
     */
    public static function onBeforeUpdate(Model $user)
    {
        if ($user->password) {
            $user->password = md5($user->password);
        }else{
            unset($user->password);
        }
        return true;
    }


}